# Sample Plugin: Transformer
#

package MT::Plugin::MyPlugin08;

use strict;
use MT;
use MT::Template::Context;
use vars qw($VERSION);
$VERSION = '0.1';

@MT::Plugin::MyPlugin08::ISA = qw(MT::Plugin);

my $plugin = new MT::Plugin::MyPlugin08({
    name => '<MT_TRANS phrase=\'_PLUGIN_NAME\'>',
    version => $VERSION,
    description => '<MT_TRANS phrase=\'_PLUGIN_DESCRIPTION\'>',
    author_name => '<MT_TRANS phrase=\'_PLUGIN_AUTHOR\'>',
    author_link => 'http://www.example.com/about/',
    doc_link => 'http://www.example.com/docs/',
    l10n_class => 'MyPlugin08::L10N',
});

MT->add_plugin($plugin);
MT->add_callback('MT::App::CMS::AppTemplateSource.cfg_simple', 9, $plugin, \&_revise_siteurl);
MT->add_callback('MT::App::CMS::AppTemplateSource.cfg_simple', 9, $plugin, \&_revise_sitepath);
MT->add_callback('MT::App::CMS::AppTemplateSource.cfg_archives', 9, $plugin, \&_revise_siteurl);
MT->add_callback('MT::App::CMS::AppTemplateSource.cfg_archives', 9, $plugin, \&_revise_sitepath);
MT->add_callback('MT::App::CMS::AppTemplateSource.cfg_archives', 9, $plugin, \&_revise_enable_archive);
MT->add_callback('MT::App::CMS::AppTemplateSource.cfg_archives', 9, $plugin, \&_revise_archiveurl);
MT->add_callback('MT::App::CMS::AppTemplateSource.cfg_archives', 9, $plugin, \&_revise_archivepath);

sub _revise_siteurl {
    my ($eh, $app, $tmpl_ref) = @_;

    my $old = <<'HTML';
<input name="site_url" id="site_url" value="<TMPL_VAR NAME=SITE_URL ESCAPE=HTML>" size="50" />
HTML
    my $new = <<'HTML';
<TMPL_IF NAME=CAN_EDIT_AUTHORS>
    <input name="site_url" id="site_url" value="<TMPL_VAR NAME=SITE_URL ESCAPE=HTML>" size="50" />
<TMPL_ELSE>
    <TMPL_VAR NAME=SITE_URL ESCAPE=HTML>
    <input type="hidden" name="site_url" value="<TMPL_VAR NAME=SITE_URL ESCAPE=HTML>" />
</TMPL_IF>
HTML

    $old = quotemeta($old);
    $$tmpl_ref =~ s/$old/$new/;
}

sub _revise_sitepath {
    my ($eh, $app, $tmpl_ref) = @_;

    my $old = <<'HTML';
<input name="site_path" id="site_path" value="<TMPL_VAR NAME=SITE_PATH ESCAPE=HTML>" size="50" />
HTML
    my $new = <<'HTML';
<TMPL_IF NAME=CAN_EDIT_AUTHORS>
    <input name="site_path" id="site_path" value="<TMPL_VAR NAME=SITE_PATH ESCAPE=HTML>" size="50" />
<TMPL_ELSE>
    <TMPL_VAR NAME=SITE_PATH ESCAPE=HTML>
    <input type="hidden" name="site_path" value="<TMPL_VAR NAME=SITE_PATH ESCAPE=HTML>" />
</TMPL_IF>
HTML

    $old = quotemeta($old);
    $$tmpl_ref =~ s/$old/$new/;
}

sub _revise_enable_archive {
    my ($eh, $app, $tmpl_ref) = @_;

    my $old = <<'HTML';
<li><input type="checkbox" name="enable_archive_paths" id="enable_archive_paths" value="1" onclick="toggleSubPrefs(this); return true"<TMPL_IF NAME=ENABLE_ARCHIVE_PATHS> checked="checked"</TMPL_IF> class="cb" /> <MT_TRANS phrase="Publish archives to alternate root path"> <a href="#" onclick="return openManual('blog_settings_publishing', 'advanced_archive_publishing')" class="help">?</a></li>
HTML
    my $new = <<'HTML';
<TMPL_IF NAME=CAN_EDIT_AUTHORS>
<li><input type="checkbox" name="enable_archive_paths" id="enable_archive_paths" value="1" onclick="toggleSubPrefs(this); return true"<TMPL_IF NAME=ENABLE_ARCHIVE_PATHS> checked="checked"</TMPL_IF> class="cb" /> <MT_TRANS phrase="Publish archives to alternate root path"> <a href="#" onclick="return openManual('blog_settings_publishing', 'advanced_archive_publishing')" class="help">?</a></li>
<TMPL_ELSE>
<li><MT_TRANS phrase="Publish archives to alternate root path"> <a href="#" onclick="return openManual('blog_settings_publishing', 'advanced_archive_publishing')" class="help">?</a></li>
</TMPL_IF>
HTML

    $old = quotemeta($old);
    $$tmpl_ref =~ s/$old/$new/;
}

sub _revise_archiveurl {
    my ($eh, $app, $tmpl_ref) = @_;

    my $old = <<'HTML';
<input name="archive_url" id="archive_url" value="<TMPL_VAR NAME=ARCHIVE_URL ESCAPE=HTML>" size="50" />
HTML
    my $new = <<'HTML';
<TMPL_IF NAME=CAN_EDIT_AUTHORS>
    <input name="archive_url" id="archive_url" value="<TMPL_VAR NAME=ARCHIVE_URL ESCAPE=HTML>" size="50" />
<TMPL_ELSE>
    <TMPL_VAR NAME=ARCHIVE_URL ESCAPE=HTML>
    <input type="hidden" name="archive_url" value="<TMPL_VAR NAME=ARCHIVE_URL ESCAPE=HTML>" />
</TMPL_IF>
HTML

    $old = quotemeta($old);
    $$tmpl_ref =~ s/$old/$new/;
}

sub _revise_archivepath {
    my ($eh, $app, $tmpl_ref) = @_;

    my $old = <<'HTML';
<input name="archive_path" id="archive_path" value="<TMPL_VAR NAME=ARCHIVE_PATH ESCAPE=HTML>" size="50" />
HTML
    my $new = <<'HTML';
<TMPL_IF NAME=CAN_EDIT_AUTHORS>
    <input name="archive_path" id="archive_path" value="<TMPL_VAR NAME=ARCHIVE_PATH ESCAPE=HTML>" size="50" />
<TMPL_ELSE>
    <TMPL_VAR NAME=ARCHIVE_PATH ESCAPE=HTML>
    <input type="hidden" name="archive_path" value="<TMPL_VAR NAME=ARCHIVE_PATH ESCAPE=HTML>" />
</TMPL_IF>
HTML

    $old = quotemeta($old);
    $$tmpl_ref =~ s/$old/$new/;
}

1;
